﻿using MathNet.Numerics;
using SeeSharpTools.JY.DSP.Utility.Filter1D;
using Sunny.UI;
using System;
using System.Data;
using System.Linq;

namespace SeeSharpTools.Demo
{
    public partial class FormInterpolate : UIPage
    {
        public FormInterpolate()
        {
            InitializeComponent();
        }

        private void uiButton_Start_Click(object sender, EventArgs e)
        {
            int r = uiIntegerUpDown_Factor.Value;
            double[] t = Generate.LinearRange(0, 1.0 / 1000, 1);
            double[] x = t.Select(num => Math.Sin(2 * Math.PI * 30 * num) + Math.Sin(2 * Math.PI * 60 * num)).ToArray();
            double[] y = Multirate.Interpolate(x, r);

            double[][] xData = new double[2][];
            double[][] yData = new double[2][];
            xData[0] = Generate.LinearRange(0, r, 120);
            xData[1] = Generate.LinearRange(0, 120);
            yData[0] = x.Take(31).ToArray();
            yData[1] = y.Take(121).ToArray();

            easyChartX1.Plot(xData, yData);
            easyChartX1.Series[0].Type = SeeSharpTools.JY.GUI.EasyChartXSeries.LineType.Bar;
            easyChartX1.Series[0].Name = "原始信号";
            easyChartX1.Series[1].Type = SeeSharpTools.JY.GUI.EasyChartXSeries.LineType.Point;
            easyChartX1.Series[1].Name = "插值信号";
        }
    }
}